from  ReadReview import Read
from datetime import *


                  
def getDateFromTime(time):
     year=int(time['year'])
     month=int(time['month'])
     day=int(time['day'])
     D= date(year,month,day)
     return D.weekday()     #return 0 if monday;  1 if tuesday and so on
 
asin0=[]
asin1=[]
asin2=[]
asin3=[]
asin4=[]
asin5=[]
asin6=[]
numof0=[]
numof1=[]
numof2=[]
numof3=[]
numof4=[]
numof5=[]
numof6=[]


 
def for0(asin):
    if(asin  in asin0 ):
        numof0[asin0.index(asin)]=numof0[asin0.index(asin)]+1
    else:
        asin0.append(asin)
        numof0.append(1)

def for1(asin):
    if(asin  in asin1 ):
        numof1[asin1.index(asin)]=numof1[asin1.index(asin)]+1
    else:
        asin1.append(asin)
        numof1.append(1)

def for2(asin):
    if(asin  in asin2 ):
        numof2[asin2.index(asin)]=numof2[asin2.index(asin)]+1
    else:
        asin2.append(asin)
        numof2.append(1)
             
def for3(asin):
    if(asin  in asin3 ):
        numof3[asin3.index(asin)]=numof3[asin3.index(asin)]+1
    else:
        asin3.append(asin)
        numof3.append(1)

def for4(asin):
    if(asin  in asin4 ):
        numof4[asin4.index(asin)]=numof4[asin4.index(asin)]+1
    else:
        asin4.append(asin)
        numof4.append(1)
        
def for5(asin):
    if(asin  in asin5 ):
        numof5[asin5.index(asin)]=numof5[asin5.index(asin)]+1
    else:
        asin5.append(asin)
        numof5.append(1)

def for6(asin):
    if(asin  in asin6 ):
        numof6[asin6.index(asin)]=numof6[asin6.index(asin)]+1
    else:
        asin6.append(asin)
        numof6.append(1)
    
def getRecommend():
    for  i in range(0,len(numof0)-1):
        for j in range(0,len(numof0)-1):
            if(numof0[j]<numof0[j+1]):
                x=numof0[j]
                numof0[j]=numof0[j+1]
                numof0[j+1]=x
                y=asin0[j]
                asin0[j]=asin0[j+1]
                asin0[j+1]=y

    for  i in range(0,len(numof1)-1):
        for j in range(0,len(numof1)-1):
            if(numof1[j]<numof1[j+1]):
                x=numof1[j]
                numof1[j]=numof1[j+1]
                numof1[j+1]=x
                y=asin1[j]
                asin1[j]=asin1[j+1]
                asin1[j+1]=y

    for  i in range(0,len(numof2)-1):
        for j in range(0,len(numof2)-1):
            if(numof2[j]<numof2[j+1]):
                x=numof2[j]
                numof2[j]=numof2[j+1]
                numof2[j+1]=x
                y=asin2[j]
                asin2[j]=asin2[j+1]
                asin2[j+1]=y

    for  i in range(0,len(numof3)-1):
        for j in range(0,len(numof3)-1):
            if(numof3[j]<numof3[j+1]):
                x=numof3[j]
                numof3[j]=numof3[j+1]
                numof3[j+1]=x
                y=asin3[j]
                asin3[j]=asin3[j+1]
                asin3[j+1]=y


    for  i in range(0,len(numof4)-1):
        for j in range(0,len(numof4)-1):
            if(numof4[j]<numof4[j+1]):
                x=numof4[j]
                numof4[j]=numof4[j+1]
                numof4[j+1]=x
                y=asin4[j]
                asin4[j]=asin4[j+1]
                asin4[j+1]=y

    for  i in range(0,len(numof5)-1):
        for j in range(0,len(numof5)-1):
            if(numof5[j]<numof5[j+1]):
                x=numof5[j]
                numof5[j]=numof5[j+1]
                numof5[j+1]=x
                y=asin5[j]
                asin5[j]=asin5[j+1]
                asin5[j+1]=y

    for  i in range(0,len(numof6)-1):
        for j in range(0,len(numof6)-1):
            if(numof6[j]<numof6[j+1]):
                x=numof6[j]
                numof6[j]=numof6[j+1]
                numof6[j+1]=x
                y=asin6[j]
                asin6[j]=asin6[j+1]
                asin6[j+1]=y
    
    print("Monday: ")
    for i in range(0,3):
                   print(asin0[i],numof0[i])
                   
    print("Tuesday: ")
    for i in range(0,3):
              print(asin1[i],numof1[i])

    print("Wednesday: ")
    for i in range(0,3):
             print(asin2[i],numof2[i])

    print("Tuesday: ")
    for i in range(0,3):
              print(asin3[i],numof3[i])

                   
    print("Friday: ")
    for i in range(0,3):
        print(asin4[i],numof4[i])

    print("Saturday: ")
    for i in range(0,3):
           print(asin5[i],numof5[i])

                   
    print("Sunday: ")
    for i in range(0,3):
              print(asin6[i],numof6[i])



if __name__ == '__main__':
   info=Read()
   list=[]
   list=info.get_infolist()
   print('complete reading file,start to analyse')
   for i in range(0,len(list)):
        asin=list[i]['ASIN']
        weekday=getDateFromTime(list[i]['time'])
        if(weekday==0):
            for0(asin)
        if(weekday==1):
            for1(asin)
        if(weekday==2):
            for2(asin)
        if(weekday==3):
            for3(asin)
        if(weekday==4):
            for4(asin)
        if(weekday==5):
            for5(asin)
        if(weekday==6):
            for6(asin)
   #end  fenleiwancheng
   print('start to recommend')
   getRecommend()
        
        